#include <iostream>
//using namespace std;
using namespace std;
int xx = 0;

int fac(int n,int m)
{
	xx++;
	cout <<"s----------------------------"<<"n-"<<n<<"  m-"<<m<<endl;
	cout <<"call num -----"<<xx<<endl;

	if(n==1) {
		
		cout <<"e----------------------------"<<"n-"<<n<<"  m-"<<m<<endl;
		return 1;
	}
	int temp = (fac(n-1,m)*n) %m;
	cout << temp <<endl;
	cout <<"e----------------------------"<<"n-"<<n<<"  m-"<<m<<endl;
 	//return (fac(n-1,m)*n) %m;
 	return temp;
}

int main()
{
 //cout<< fac(12,12345); //be 3255
 //cout<<endl;
 //cout << fac(100,12345); //7290
 cout<<fac(5,7);
 return 0;	
}
